﻿function getADCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=")
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1
            c_end = document.cookie.indexOf(";", c_start)
            if (c_end == -1) c_end = document.cookie.length
            return unescape(document.cookie.substring(c_start, c_end))
        }
    }
    return ""
}

function SetAccurateDirectValue() {
    if (typeof (ad_AccurateDirect) != "undefined") {       
        var ad_AccurateDirects = ad_AccurateDirect.split(",");
        if (ad_AccurateDirects.length >= 5) {

            ad_LevelID = ad_AccurateDirects[0];
            ad_PriceIntervalID = ad_AccurateDirects[1];
            if (ad_PriceIntervalID.indexOf('_') > -1) {
                ad_PriceIntervalID = ad_PriceIntervalID.split("_")[0];
            }
            ad_UserBrandID = ad_AccurateDirects[2];
            ad_UserTypeID = ad_AccurateDirects[3];
            ad_BuyStageID = ad_AccurateDirects[4];
        }
    }
}
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}     
try
{
    // var datatype = GetQueryString("datatype");
    var datatype = "seque";
    var ad_sessionid = getADCookie("sessionid");
    var ad_advalue = getADCookie("AccurateDirect" + datatype);
    if ((datatype == "seque" || datatype == "mediav") && ad_advalue == '' && typeof (ad_sessionid) != "undefined" && ad_sessionid.length>0) {
       
        document.write('<script type="text/javascript" src="http://accuratedirect.autohome.com.cn/AccurateDirect.aspx?id=' + ad_sessionid + '&datatype=' + datatype + '"></scr' + 'ipt>');
    }
    else {
        document.write('<script type="text/javascript">var ad_AccurateDirect ="' + ad_advalue.toString() + '";</scr' + 'ipt>');
    }
    var ad_LevelID = '';
    var ad_PriceIntervalID = '';
    var ad_UserBrandID = '';
    var ad_UserTypeID = '';
    var ad_BuyStageID = '';
    SetAccurateDirectValue();
    
}
catch (e) 
{
    document.write('<script type="text/javascript">var ad_AccurateDirect ="404";</scr' + 'ipt>');
}

